//
//  LRXHelpMesgCell.m
//  路人侠
//
//  Created by zhangxulong on 2/13/16.
//  Copyright © 2016 zhangxulong. All rights reserved.
//

#import "LRXHelpMesgCell.h"
#import "LRXSpotView.h"
#import "LRXThing.h"
#import "zxlCircleView.h"
#import "LRXuserView.h"
#import "LRXHelpMoreInfoView.h"

@interface LRXHelpMesgCell()
@property (nonatomic,strong) UILabel * stLabel;
@property (nonatomic,strong) UILabel * endLabel;
@property (nonatomic,strong) zxlCircleView * stSpot;
@property (nonatomic,strong) zxlCircleView * endSpot;
@property (nonatomic,strong) UILabel * thingGather;
@property (nonatomic,strong) UILabel * thingMoney;
@property (nonatomic,strong) UILabel * startTime;
@property (nonatomic,strong) UILabel * endTime;
@property (nonatomic,strong) UIImageView * jiantou;
@property (nonatomic,weak) LRXHelpMeInfoModel * model;
@property (nonatomic,strong) UIImageView * sendHomeImage;
@end

@implementation LRXHelpMesgCell



- (void)layoutSubviews :(LRXHelpMeInfoModel *)model
{

    
    
    self.model = model;
    CGFloat addrFont = 28 * hScale;
    CGFloat detailFont = 25 * hScale;
    CGFloat timeFont = 40 * hScale;
    CGFloat spotRadius = 8 * hScale;
    CGFloat stLabelW = 390 * wScale;
    CGFloat stLabelH = 24 * hScale;
    CGFloat stlabelY = 35 * hScale;
    CGFloat userViewY = 20 * hScale;
    
    self.stLabel = [[UILabel alloc]init];
    self.endLabel = [[UILabel alloc]init];
    
    self.stLabel.textColor = [UIColor blackColor];

    self.stLabel.font = [UIFont systemFontOfSize:addrFont];
    self.stLabel.frame = CGRectMake(162 * wScale, stlabelY, stLabelW, stLabelH);
    

    
    
    //开始点
    CGPoint stPoint = CGPointMake(138 * wScale, self.stLabel.center.y);
    self.stSpot = [[zxlCircleView alloc]init];
    self.stSpot.imageName = @"stSpot";
    self.stSpot.borderColor = [UIColor clearColor];
    self.stSpot.lineWidth = 0;
    self.stSpot.frame = CGRectMake(0, 0, spotRadius, spotRadius);
    self.stSpot.center = stPoint;
    self.stSpot.backgroundColor = [UIColor clearColor];
    

    
    //头像的设置
    self.userView = [[UIImageView alloc]init];
    self.userView.frame = CGRectMake(30 * wScale, userViewY, 85 * wScale, 85 * wScale);
    self.userView.layer.cornerRadius = self.userView.frame.size.height * 0.5;
    self.userView.layer.masksToBounds = YES;

    
    //设置物品具体显示标签
    self.thingGather = [[UILabel alloc]init];
    self.thingMoney = [[UILabel alloc]init];
    self.thingGather.textColor = [UIColor colorWithRed:101 green:101 blue:101];
    self.thingGather.font = [UIFont systemFontOfSize:detailFont];
    self.thingMoney.textColor = [UIColor colorWithRed:69 green:136 blue:241];
    self.thingMoney.font = self.thingGather.font;


    
    CGFloat thingGatherX = CGRectGetMaxX(self.stSpot.frame);
    CGFloat thingGatherY = stlabelY + 60 * hScale;
    
    self.thingGather.frame = CGRectMake(thingGatherX, thingGatherY, 0, 0);
    CGFloat thingMoenyX = CGRectGetMaxX(self.userView.frame) + 120 * wScale;
    self.thingMoney.frame = CGRectMake(thingMoenyX, thingGatherY, 0,0);
    
 
    //设置时间的标签
    self.startTime = [[UILabel alloc]init];
    self.endTime = [[UILabel alloc]init];
    
    self.startTime.textColor = [UIColor colorWithRed:247 green:203 blue:75];
    self.endTime.textColor = self.startTime.textColor;
    self.endTime.font = [UIFont systemFontOfSize:timeFont];
    self.startTime.font = self.endTime.font;
    
    
    
    
    CGFloat sendHomeImageW = 50 * wScale;
    CGFloat sendHomeImageH = 70 * hScale;
    self.sendHomeImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"sendHome"]];
    self.sendHomeImage.frame = CGRectMake(MainScreenW - 80 * hScale, 0, sendHomeImageW, sendHomeImageH);
    
    CGRect sendLabelRect = CGRectMake(0, 0, self.sendHomeImage.frame.size.width, 50 * hScale);
    UILabel * sendHomeLabel = [[UILabel alloc]initWithFrame:sendLabelRect];
    sendHomeLabel.textAlignment = NSTextAlignmentCenter;
    sendHomeLabel.numberOfLines = 0;
    sendHomeLabel.text = @"送货上楼";
    sendHomeLabel.textColor = [UIColor whiteColor];
    sendHomeLabel.font = [UIFont systemFontOfSize:17 * hScale];
    
    [self.sendHomeImage addSubview:sendHomeLabel];
    [self addSubview:self.sendHomeImage];
    

    [self setHelpMesgCellModel:model];

    [self addSubview:self.jiantou];
    [self addSubview:self.startTime];
    [self addSubview:self.endTime];
    [self addSubview:self.thingGather];
    [self addSubview:self.thingMoney];
    [self addSubview:self.userView];
    
    [self addSubview:self.stLabel];
    [self addSubview:self.stSpot];

}

//设置cell的内容
- (void)setHelpMesgCellModel:(LRXHelpMeInfoModel *)model
{
    //开始地点和结束地点
    self.stLabel.text = model.sendAddr;
    self.endLabel.text = model.buyAddr;
     CGFloat userViewY = 20 * hScale;
    //用 SDWeBImage
    NSString * imageStr = model.userIcon;
    if (![imageStr isEqual:[NSNull null]] && imageStr)
    {
        imageStr = [routeImageUrl stringByAppendingString:imageStr];
        
    }else
    {
        imageStr = @"";
    }
    
    //转UTF8 编码
    imageStr = [imageStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    
    NSURL * imageUrl = [NSURL URLWithString: imageStr];
    
    [self.userView sd_setImageWithURL:imageUrl placeholderImage:[UIImage imageNamed:@"de"]];
    self.userView.frame = CGRectMake(30 * wScale, userViewY, 85 * wScale, 85 * wScale);
    self.userView.layer.cornerRadius = self.userView.frame.size.height * 0.5;
    self.userView.layer.masksToBounds = YES;
    
    self.thingGather.text = [NSString stringWithFormat:@"物品: %ld件",model.thingArray.count];
    [self.thingGather sizeToFit];
    
    CGFloat sumMoney = 0;
    for (LRXThing * thing in model.thingArray) {sumMoney += [thing.thingMoney floatValue];}
    self.thingMoney.text = [NSString stringWithFormat:@"总金额:%.2lf元(含小费%@元)",sumMoney * 1.1,model.tip];
    
    self.thingMoney.frame = CGRectMake(CGRectGetMaxX(self.thingGather.frame) + 20 * wScale, self.thingMoney.frame.origin.y, 0, 0);
    [self.thingMoney sizeToFit];
    
    self.startTime.text = [NSString stringWithFormat:@"%@",model.startTime];
    self.endTime.text = [NSString stringWithFormat:@"%@",model.endTime];

    
    CGFloat startTimeY = CGRectGetMaxY(self.thingMoney.frame) + 30 * hScale;
    self.startTime.frame = CGRectMake(CGRectGetMaxX(self.stSpot.frame), startTimeY, 0, 0);
    [self.startTime sizeToFit];
    
    CGFloat jiantouH = 17 * hScale;
    CGFloat jiantouX = CGRectGetMaxX(self.startTime.frame) + 16 * wScale;
    CGFloat jiantouY = startTimeY + self.startTime.frame.size.height * 0.5 - jiantouH * 0.5;
    
    self.jiantou = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"jiantou"]];
    self.jiantou.frame = CGRectMake(jiantouX, jiantouY, 25 * wScale ,jiantouH);
    
    CGFloat endTimeX = CGRectGetMaxX(self.jiantou.frame) + 16 * wScale;
    self.endTime.frame = CGRectMake(endTimeX, startTimeY, 0, 0);
    [self.endTime sizeToFit];
    
    
    CGFloat cellHeight = CGRectGetMaxY(self.startTime.frame) + 15 * hScale;
    self.cellHeight = cellHeight;
    
    if ([model.is_home_delivery isEqualToString:@"0"]) {
        self.sendHomeImage.hidden = YES;
    }
    else
    {
        self.sendHomeImage.hidden = NO;
    }

}





@end
